package be.kuleuven.mume.paginas;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import be.kuleuven.mume.R;
import be.kuleuven.mume.framework.Antwoord;
import be.kuleuven.mume.framework.Vraag;

public class AntwoordEditPagina extends Activity{
	private Antwoord antwoord;
	private EditText mText;
	private TextView mAntwoordTitle;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
	    setContentView(R.layout.antwoord_edit);	    
	    
	    if ( customTitleSupported ) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
        }
	    
	    Bundle extras = getIntent().getExtras();
	    Vraag vraag = (Vraag)extras.get(Vraag.VRAAG);
	    antwoord = (Antwoord)extras.get(Antwoord.ANTWOORD);
	    if(antwoord == null) {
	    	antwoord = new Antwoord();
	    	antwoord.setVraagId(vraag.getId());
	    }

        final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
        if ( myTitleText != null ) {
            myTitleText.setText(vraag.getSubject());
        }

	    mText = (EditText) findViewById(R.id.antwoord_text);
	    mText.setText(antwoord.getText());
	    mAntwoordTitle = (TextView) findViewById(R.id.antwoord_vraag);
	    mAntwoordTitle.setText(vraag.getText());

	    Button confirmButton = (Button) findViewById(R.id.senda_btn);

	    confirmButton.setOnClickListener(new View.OnClickListener() {

	        public void onClick(View view) {
	            Bundle bundle = new Bundle();
	            
	            antwoord.setText(mText.getText().toString());
	            bundle.putSerializable(Antwoord.ANTWOORD, antwoord);

	            Intent mIntent = new Intent();
	            mIntent.putExtras(bundle);
	            setResult(RESULT_OK, mIntent);
	            finish();
	        }
	    });
	}
}
